package com.nike.amoeba;

import android.util.Log;

import org.json.JSONArray;
import org.json.JSONObject;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

import java.util.function.Consumer;

import io.reactivex.rxjava3.core.BackpressureStrategy;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.FlowableEmitter;
import io.reactivex.rxjava3.core.FlowableOnSubscribe;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * @Author
 * @Date 2023/8/9 15:48
 * @Description
 */
public class a  {

    public void aa(){
        JSONArray ja = new JSONArray();
        for (int i = 0;i< ja.length();i++){
            JSONObject jsonObject = ja.optJSONObject(i);
        }


        StringBuffer sb = new StringBuffer();
        String[] split = sb.toString().split(",");
        for (int i = 0;i<split.length;i++){
            String s = split[i];
        }

        for (int i = 0;i<10;i++){

        }

    }

    public void flowable(){
        Flowable.create((FlowableOnSubscribe<Integer>) e -> {
            for(int j = 0;j<=150;j++){
                e.onNext(j);
                try{
                    Thread.sleep(50);
                }catch (Exception ex){
                }
            }
        }, BackpressureStrategy.ERROR)
                .subscribeOn(Schedulers.newThread())
                .observeOn(Schedulers.newThread())
                .subscribe(new Subscriber<Integer>() {
                    @Override
                    public void onSubscribe(Subscription s) {
                        s.request(Long.MAX_VALUE); //观察者设置接收事件的数量,如果不设置接收不到事件
                    }
                    @Override
                    public void onNext(Integer integer) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    @Override
                    public void onError(Throwable t) {
                    }
                    @Override
                    public void onComplete() {
                    }
                });
    }



}
